cmake_minimum_required(VERSION 3.20)

set(CMAKE_CXX_STANDARD 17)

# 项目名称
set(TARGET_NAME AlgebraTest)
set(PROJECT_NAME AlgebraTest)
#project(AlgebraTest LANGUAGES CXX)

# message(STATUS "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")

if (MINGW)
# 编译参数 先不考虑MSVC
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -Wa,-mbig-obj")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall -Wa,-mbig-obj")
endif()


#################################################################################
# Specify rules to build the target(s).

set(TARGET_HDRS
)

set(TARGET_SRCS
  GraphTest.cpp
  MathToolsTest.cpp
  MatrixTest.cpp
  PointTest.cpp
  ToolsTest.cpp
  Vector3DTest.cpp
  ODETest.cpp
  EigenSpaceTest.cpp
  main.cpp
)

set(TARGET_LIBS
    PRIVATE Algebra
)

# GTest
# find_package(GTest REQUIRED)
# list(APPEND TARGET_LIBS GTest::gtest)

# MPI
if (SG_USE_MPI)
  list(APPEND TARGET_SRCS MpiTest.cpp)

  # PETSc
  list(APPEND TARGET_SRCS PetscTest.cpp)

  # oneMKL
  if(SG_USE_MKL)
    list(APPEND TARGET_SRCS CPardisoTest.cpp)
  endif()  

  # ARPACK
  if(SG_USE_ARPACK)
    list(APPEND TARGET_SRCS PArpackTest.cpp)
  endif()

else()
  # Eigen
  list(APPEND TARGET_SRCS EigenTest.cpp)

  # SuperLU
  if(SG_USE_SUPERLU)
    list(APPEND TARGET_SRCS SuperLUTest.cpp)
  endif()

  # oneMKL
  if(SG_USE_MKL)
    list(APPEND TARGET_SRCS PardisoTest.cpp)
    list(APPEND TARGET_SRCS SparseBlasTest.cpp)
  endif()

  # ARPACK
  if(SG_USE_ARPACK)
    list(APPEND TARGET_SRCS ArpackTest.cpp)
  endif()

endif ()

# CUDA
if (SG_USE_CUDA)
  list(APPEND TARGET_SRCS CudaTest.cpp)
endif ()


# 获取此项目源文件
set(SOURCES
  ${TARGET_HDRS}
  ${TARGET_SRCS}
)

add_executable(${TARGET_NAME} ${SOURCES})

# 设置头文件查找目录
target_include_directories(
  ${TARGET_NAME}
#  PRIVATE ${CMAKE_SOURCE_DIR}
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..
  PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..  
  PRIVATE ${CMAKE_INSTALL_PREFIX}/include/  
)

# 链接库
target_link_directories(${TARGET_NAME} PRIVATE ${CMAKE_INSTALL_PREFIX}/lib)
target_link_libraries(${TARGET_NAME} ${TARGET_LIBS})

# # verbose diagnostic messages for the 'Debug' configurations
# # _DEBUG Defined as 1 when the /LDd, /MDd, or /MTd compiler option is set. Otherwise, undefined.
# # see https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170#standard-predefined-identifier
# if (CMAKE_BUILD_TYPE MATCHES "[D|d]ebug")
# target_compile_definitions(${TARGET_NAME} PRIVATE SG_DEBUG)
# endif()

import_gtest()

#################################################################################
# Specify rules to run at install time.

# associates the installed target files with an export taget.
# see https://cmake.org/cmake/help/v3.7/command/install.html#installing-targets
# install(TARGETS ${TARGET_NAME})